package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.CorpWeChatUser;
import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerCostEstimation;
import com.shrcl.engineerprocess.domain.EngineerNotificationCorpWeiXinSender;
import com.shrcl.engineerprocess.domain.EngineerNotifyReceiver;
import com.shrcl.engineerprocess.domain.EngineerProjectInitNotification;
import com.shrcl.engineerprocess.domain.EngineerTraining;
import com.shrcl.engineerprocess.domain.Notification;
import com.shrcl.engineerprocess.domain.NotifyReceiver;
import com.shrcl.engineerprocess.domain.ServiceRequestInfo;
import com.shrcl.engineerprocess.domain.TaskNotification;
import com.shrcl.engineerprocess.domain.TrainingNotification;
import com.shrct.businessprocess.organization.RCEnterprise;
import edu.fudan.mylang.pf.BaseService;
import java.util.ArrayList;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.springframework.stereotype.Service;
import wechat.app.corp.domain.EngineerNotificationCorpWeChat;

@Service("com.shrcl.engineerprocess.domain.EngineerNotificationCorpWeiXinSender")
public class EngineerNotificationCorpWeiXinSenderImpl extends BaseService implements EngineerNotificationCorpWeiXinSender {
  public void sendTaskMesssage2WXUser(final TaskNotification n) {
    NotifyReceiver _receiver = n.getReceiver();
    Engineer _engineer = ((EngineerNotifyReceiver) _receiver)==null?(Engineer)null:((EngineerNotifyReceiver) _receiver).getEngineer();
    final CorpWeChatUser usr = _engineer==null?(CorpWeChatUser)null:_engineer.asActiveCorpWechatUser();
    boolean _and = false;
    boolean _notEquals = (!Objects.equal(usr, null));
    if (!_notEquals) {
      _and = false;
    } else {
      Boolean _excluded = usr.getExcluded();
      boolean _equals = ((_excluded).booleanValue() == false);
      _and = (_notEquals && _equals);
    }
    if (_and) {
    }
  }
  
  public void sendTaskMesssage2WXUserMock(final TaskNotification n) {
  }
  
  public void sendTrainingMesssage2WXUser(final TrainingNotification n) {
  }
  
  public void sendTrainingMesssage2WXUseMock(final TrainingNotification n) {
    EngineerTraining _engineerTraining = n.getEngineerTraining();
    String _name = _engineerTraining.getName();
    String _plus = ("[" + _name);
    final String sub = (_plus + "]\u57F9\u8BAD\u901A\u77E5");
    EngineerTraining _engineerTraining_1 = n.getEngineerTraining();
    Date _startdate = _engineerTraining_1.getStartdate();
    String _localeString = _startdate.toLocaleString();
    String _plus_1 = ("\n\u57F9\u8BAD\u65E5\u671F:" + _localeString);
    String _plus_2 = (_plus_1 + "\n");
    String _plus_3 = (_plus_2 + "\u57F9\u8BAD\u5730\u70B9:");
    EngineerTraining _engineerTraining_2 = n.getEngineerTraining();
    String _location = _engineerTraining_2.getLocation();
    String _plus_4 = (_plus_3 + _location);
    String _plus_5 = (_plus_4 + "\n\u57F9\u8BAD\u5185\u5BB9:");
    EngineerTraining _engineerTraining_3 = n.getEngineerTraining();
    String _topic = _engineerTraining_3.getTopic();
    final String body = (_plus_5 + _topic);
    NotifyReceiver _receiver = n.getReceiver();
    Engineer _engineer = ((EngineerNotifyReceiver) _receiver).getEngineer();
    CorpWeChatUser _wechatUser = _engineer==null?(CorpWeChatUser)null:_engineer.getWechatUser();
    final String wid = _wechatUser==null?(String)null:_wechatUser.getWechatid();
    ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(wid);
    Long _id = n.getId();
    String _string = _id.toString();
    EngineerNotificationCorpWeChat.sendNormalNotification(_newArrayList, sub, body, _string);
  }
  
  public void sendEngineerProject2WXUseMock(final EngineerProjectInitNotification n) {
    EngineerCostEstimation _engineerCostEstimation = n.getEngineerCostEstimation();
    ServiceRequestInfo _requestInfo = _engineerCostEstimation.getRequestInfo();
    String _projectName = _requestInfo.getProjectName();
    String _plus = ("TSC[" + _projectName);
    final String sub = (_plus + "]\u670D\u52A1\u7ACB\u9879\u901A\u77E5");
    String _plus_1 = ("\u8BF7\u8FDB\u884C\u670D\u52A1\u7ACB\u9879:" + "\nTSC\u540D\u79F0\uFF1A");
    EngineerCostEstimation _engineerCostEstimation_1 = n.getEngineerCostEstimation();
    ServiceRequestInfo _requestInfo_1 = _engineerCostEstimation_1.getRequestInfo();
    String _projectName_1 = _requestInfo_1.getProjectName();
    String _plus_2 = (_plus_1 + _projectName_1);
    String _plus_3 = (_plus_2 + "\n\u5BA2\u6237\u540D\u79F0\uFF1A");
    EngineerCostEstimation _engineerCostEstimation_2 = n.getEngineerCostEstimation();
    ServiceRequestInfo _requestInfo_2 = _engineerCostEstimation_2.getRequestInfo();
    RCEnterprise _customer = _requestInfo_2.getCustomer();
    String _name = _customer.getName();
    String _plus_4 = (_plus_3 + _name);
    String _plus_5 = (_plus_4 + "\n\u552E\u540E\u7ECF\u7406\uFF1A");
    EngineerCostEstimation _engineerCostEstimation_3 = n.getEngineerCostEstimation();
    Engineer _postSaleManager = _engineerCostEstimation_3.getPostSaleManager();
    String _name_1 = _postSaleManager.getName();
    final String body = (_plus_5 + _name_1);
    NotifyReceiver _receiver = n.getReceiver();
    Engineer _engineer = ((EngineerNotifyReceiver) _receiver).getEngineer();
    CorpWeChatUser _wechatUser = _engineer.getWechatUser();
    final String wid = _wechatUser.getWechatid();
    try {
      ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(wid);
      Long _id = n.getId();
      String _string = _id.toString();
      EngineerNotificationCorpWeChat.sendNormalNotification(_newArrayList, sub, body, _string);
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        e.printStackTrace();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  
  public void send(final Notification n) {
    if ((n instanceof TaskNotification)) {
      this.sendTaskMesssage2WXUserMock(((TaskNotification) n));
    } else {
      if ((n instanceof TrainingNotification)) {
        this.sendTrainingMesssage2WXUseMock(((TrainingNotification) n));
      } else {
        if ((n instanceof EngineerProjectInitNotification)) {
          this.sendEngineerProject2WXUseMock(((EngineerProjectInitNotification) n));
        }
      }
    }
  }
}
